package com.example.sam.widgettest414_fzh;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
   private TextView tv;
    private EditText et;
    private Button btngettext,btnsetimg;
    private ImageView iv;
    private ImageButton ibtn;

    private RadioGroup rg;
    private RadioButton rbnan,rbnv;
    private CheckBox cblan,cbzu,cbyou;
    private Button btngetgender,btngetfun;
    private String strfun="";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    init();
    }

    private void init() {
        //获取那六个控件
        tv=(TextView)findViewById(R.id.textView2);
        et=(EditText)findViewById(R.id.editText2);
        btngettext=(Button)findViewById(R.id.button5);
        btnsetimg=(Button)findViewById(R.id.button6);
        iv=(ImageView)findViewById(R.id.imageView3);
        ibtn=(ImageButton) findViewById(R.id.imageButton3);
        //监听器
        btngettext.setOnClickListener(this);
        btnsetimg.setOnClickListener(this);

        ibtn.setOnClickListener(this);
        rg=(RadioGroup)findViewById(R.id.radiogroup);
        rbnv=(RadioButton)findViewById(R.id.radioButton);
        rbnan=(RadioButton)findViewById(R.id.radioButton3);
        cblan=(CheckBox) findViewById(R.id.checkBox5);
        cbzu=(CheckBox) findViewById(R.id.checkBox6);
        cbyou=(CheckBox) findViewById(R.id.checkBox7);
        btngetgender=(Button) findViewById(R.id.button7);
        btngetfun=(Button) findViewById(R.id.button9);
        btngetgender.setOnClickListener(this);
        btngetfun.setOnClickListener(this);
        cblan.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked)
                    strfun+="排球+";
                else
                    strfun=strfun.replace("排球+","");
                tv.setText(strfun);
            }
        });
        cbzu.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked)
                    strfun+="足球+";
                else
                    strfun=strfun.replace("足球+","");
                tv.setText(strfun);
            }
        });
        cbyou.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked)
                    strfun+="篮球+";
                else
                    strfun=strfun.replace("篮球+","");
                tv.setText(strfun);
            }
        });
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch(checkedId)
                {
                    case R.id.radioButton:
                        tv.setText("男");
                        break;
                    case R.id.radioButton3:
                        tv.setText("女");
                        break;
                }
            }
        });
    }
    public void onClick(View view){
        switch (view.getId())
        {
            case R.id.button5:
                String str=et.getText().toString();
                tv.setText(str);
                break;
            case R.id.button6:
                iv.setImageResource(R.drawable.pic2);
                break;
            case R.id.imageButton3:
                Intent intent = new Intent(MainActivity.this,NewActivity.class);
                intent.putExtra("param1",et.getText().toString());
                intent.putExtra("param2",3);
                startActivity(intent);
                break;
            case R.id.button7:
                if(rbnan.isChecked()) tv.setText("男");
                if(rbnv.isChecked()) tv.setText("女");
            case R.id.button9:
                String msg="";
                if(cblan.isChecked()) msg+="1";
                if(cbzu.isChecked()) msg+="2";
                if(cbyou.isChecked()) msg+="3";
        }
    }
}
